package com.spider.dao.hbase;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;

public class HBaseTest {
	
	public static Configuration conf;
	static {
		conf=HBaseConfiguration.create();
		conf.set("hbase.rootdir","hdfs://master1:9000/hbase" );
        conf.set("hbase.zookeeper.quorum", "slave1,slave2");
	}
	
	public static void CreatTable(String tableName) throws Exception
	{
		HBaseAdmin admin =new HBaseAdmin(conf);
		if(admin.tableExists(tableName)) {
			System.out.println("���Ѵ��ڡ�");
		}
		else {
			HTableDescriptor tableDescriptor=new HTableDescriptor(tableName);
			tableDescriptor.addFamily(new HColumnDescriptor("cf1"));
			admin.createTable(tableDescriptor);
			System.out.println("������"+tableName+"�ɹ���");
		}
		
		
		Put put =new Put("123".getBytes());
		put.add("cf1".getBytes(), "colum1".getBytes(), "value1".getBytes());
		put.add("cf1".getBytes(), "colum2".getBytes(), "value2".getBytes());
		put.add("cf1".getBytes(), "colum3".getBytes(), "value3".getBytes());
		
		Put put2 = new Put("234".getBytes());
		put2.add("cf1".getBytes(), "colum1".getBytes(), "value1".getBytes());
		put2.add("cf1".getBytes(), "colum2".getBytes(), "value2".getBytes());
		put2.add("cf1".getBytes(), "colum3".getBytes(), "value3".getBytes());
		
		HTable table =new HTable(conf,tableName);
		table.put(put);
		table.put(put2);
		System.out.println("������ݳɹ���");
	}
	
	public void deleteRow(String tableName,String wrowKey,String rowKey2) throws Exception{
		HTable table =new HTable(conf,tableName);
		
	}
}
